
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.baumi.tankwars.entities;

/**
 *
 * @author Michael Baumgartner
 */
public abstract class BlockEntity2D implements Entity2D {

    protected double x;
    protected double y;
    protected double width;
    protected double height;
    protected boolean destroy;

    public BlockEntity2D(double x, double y, double width, double height) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
        destroy = false;
    }

    @Override
    public double getX() {
        return x;
    }

    @Override
    public double getY() {
        return y;
    }

    @Override
    public void setX(double x) {
        this.x = x;

    }

    @Override
    public void setY(double y) {
        this.y = y;

    }

    public double getxMin() {
        return x - width / 2;
    }

    public double getxMax() {
        return x + width / 2;
    }

    public double getyMin() {
        return y - height / 2;
    }

    public double getyMax() {
        return y + height / 2;
    }

    @Override
    public void setLocation(double x, double y) {
        this.x = x;
        this.y = y;
    }

    public boolean isDestroy() {
        return destroy;
    }

    public void setDestroy(boolean destroy) {
        this.destroy = destroy;
    }

    public boolean intersects(BlockEntity2D otherEntity) {
        if (this.getxMin() > otherEntity.getxMax()) {
            return false;
        }
        if (this.getxMax() < otherEntity.getxMin()) {
            return false;
        }
        if (this.getyMin() > otherEntity.getyMax()) {
            return false;
        }
        if (this.getyMax() < otherEntity.getyMin()) {
            return false;
        }
        return true;
    }

    @Override
    public void destroy() {
        setDestroy(true);
    }

    public abstract void collideWith(BlockEntity2D otherEntity);

    public abstract void setUp();

    public abstract void draw();
}
